#ifndef DATABASETOOL_H
#define DATABASETOOL_H

#include <QObject>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <mutex>
#include "mytypes.h"

namespace Yzty
{
    class DataBaseTool : public QObject
    {
        Q_OBJECT
    public:
        static std::mutex qmutex;
        static DataBaseTool* GetInsatnce(QObject* parent = nullptr);
        virtual ~DataBaseTool();
        bool Transaction();
        bool RollBack();
        bool Commit();
        bool SetDataBaseName(const QString& name);      //设置数据库的名字
        bool Execute(const QString& query);             //执行sql语句
        bool IsContain(const QString& name);            //当前数据库的名称
        QVector<QStringList> GetResult();               //获取执行结果

    private:
        explicit DataBaseTool(QObject *parent = nullptr);
        static DataBaseTool* _instance;

    signals:

    public slots:

    private:
        QSqlDatabase sql;
        QSqlQuery* query;
    };
};

#endif // DATABASETOOL_H
